home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
listings
/
v_11_06
/
1106133b
< prev
next >
Wrap
Text File
|
1993-02-26
|
590b
|
34 lines
/* stderr.c: Redirect stderr */
#include <stdio.h>
#include <io.h>
#include <fcntl.h>
#include <assert.h>
#include <sys/types.h>
#include <sys/stat.h>
static int old_handle = -1;
int redir_stderr(char *fname)
{
int fd = open(fname,O_WRONLY|O_CREAT|O_TEXT,S_IWRITE);
assert(fd >= 0);
old_handle = dup(fileno(stderr));
dup2(fd,fileno(stderr));
close(fd);
return fd;
}
void restore_stderr()
{
if (old_handle != -1)
{
dup2(old_handle,fileno(stderr));
close(old_handle);
old_handle = -1;
}
}